/*
 * Copyright (c) 2016 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.common.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @author zhangcm
 * @version 1.0, 2017/8/27
 */
public class TokenUtils {

    public static final String TOKEN_NAME = "token";

    private TokenUtils(){}

    public static String getFromHeader(HttpServletRequest request){
        return request.getHeader(TOKEN_NAME);
    }

    public static String getFromCookie(HttpServletRequest request){
        Cookie cookie = CookieUtils.getCookie(request, TOKEN_NAME);
        return null == cookie ? null : cookie.getValue();
    }

    public static String create(){
        String uuid = UUID.randomUUID().toString();
        return uuid;
    }
}
